import { login } from '@/api/user.js'
import { getToken, setToken, removeToken } from '@/utils/auth'
const state = {
  userInfo: {},
  toKen: getToken()
}
const mutations = {
  getUserInfo(state,step) {
    state.userInfo = step
  },
  setToken(state, data) {
    state.toKen = data // 设置token
    setToken(data) // vuex和缓存同步token
  },
  removeToken (state) {
    state.toKen = null
    removeToken()
  }

}
const actions = {
  async login (context, data) {
    const result = await login(data)
    console.log(result);
    context.commit('setToken', result)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

